package cn.springboot.erp.service.impl;

import cn.springboot.erp.commons.QueryParams;
import cn.springboot.erp.commons.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.springboot.erp.entity.LogInfo;
import cn.springboot.erp.service.LogInfoService;
import cn.springboot.erp.mapper.LogInfoMapper;
import org.springframework.stereotype.Service;

/**
* @author asus
* @description 针对表【log_info】的数据库操作Service实现
* @createDate 2024-05-08 17:12:06
*/
@Service
public class LogInfoServiceImpl extends ServiceImpl<LogInfoMapper, LogInfo>
    implements LogInfoService{

    @Override
    public ResponseResult listPage(QueryParams<LogInfo> queryParams) {
        // 获取分页数据
        LogInfo searchParams = queryParams.getSearchParams();
        Integer page = queryParams.getPage();
        Integer limit = queryParams.getLimit();
        // 数据分页
        Page<LogInfo> logInfoPage = new Page<>(page, limit);
        //数据查询
        LambdaQueryWrapper<LogInfo> lambda = new QueryWrapper<LogInfo>().lambda();
        lambda.eq(StringUtils.isNotBlank(searchParams.getUsername()),LogInfo::getUsername,searchParams.getUsername())
                .eq(StringUtils.isNotBlank(searchParams.getModel()),LogInfo::getModel,searchParams.getModel())
                .eq(StringUtils.isNotBlank(searchParams.getIp()),LogInfo::getIp,searchParams.getIp())
                .orderByDesc(LogInfo::getCreateTime);
        baseMapper.selectPage(logInfoPage,lambda);
        return ResponseResult.Success()
                .data("total",logInfoPage.getTotal())
                .data("logInfoList",logInfoPage.getRecords());
    }
}




